<?php
namespace app\common\extract;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory as IOFactory;

class Excel{

    public static function createFile($array = array(), $path){
        if(!is_dir(pathinfo($path)['dirname'])){
            throw new \Exception('文件夹不存在');
        }
        $spreadsheet = new Spreadsheet();
        $columnArray = array_chunk($array, 1);
        $spreadsheet->getActiveSheet()->fromArray($columnArray, null, "A1");
        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save($path);
    }
}